package com.example.service.impl;

import com.example.dao.ActivityCollectionDao;
import com.example.entity.ActivityCollection;
import com.example.service.ActivityCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ActivityCollectionServiceImpl implements ActivityCollectionService {

    @Autowired
    private ActivityCollectionDao activityCollectionDao;

    @Override
    public boolean addCollection(ActivityCollection collection) {
        if (isActivityCollected(collection.getVolunteer().getVolunteer_id(), collection.getActivity().getActivityId())) {
            return false;
        }
        return activityCollectionDao.insert(collection) > 0;
    }

    @Override
    public boolean deleteCollection(Integer collection_id) {
        return activityCollectionDao.deleteById(collection_id) > 0;
    }
    @Override
    public List<ActivityCollection> getCollectionsByVolunteerId(Integer volunteer_id) {
        return activityCollectionDao.selectByVolunteerId(volunteer_id);
    }

    @Override
    public boolean isActivityCollected(Integer volunteer_id, Integer activityId) {
        return activityCollectionDao.existsByVolunteerAndActivity(volunteer_id, activityId);
    }

    @Override
    public ActivityCollection getCollectionDetail(Integer collection_id) {
        return activityCollectionDao.selectById(collection_id);
    }
}